package comWorld.favorite.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import comWorld.blog.BlogInfo;
import comWorld.blog.BlogInfoManage;
import comWorld.blog.BlogInfos;
import comWorld.favorite.FavoriteManage;
import comWorld.social.VisitorCount;

/**
 * Servlet implementation class FavoritesPageInit
 */
@WebServlet("/favorites")
public class FavoritesPageInit extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FavoritesPageInit() {
        super();
    }

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int userId = (int) request.getAttribute("userId");
		VisitorCount visitorCount = VisitorCount.getLastVisitorCount(userId);
		visitorCount.add();
		request.setAttribute("visitorCount", visitorCount);
		List<BlogInfo> blogInfos = FavoriteManage.getBlogFavorites(userId).getBlogs();
		request.setAttribute("blogInfos", blogInfos);
		request.getRequestDispatcher("/user/favorites.jsp").forward(request, response);
	}

}
